#region Using directives
using System;
using System.Text;
using System.Data;
using System.Collections;
using WP.MF.DataEntity;
using WP.MF.DataAccess;
using WP.MF.BusinessRule;
using WP.DB;
using WP.Commons;
using System.Windows.Forms;
#endregion

namespace WP.MF.BusinessLogical
{
    public class MRLPriceByCatgBLL : IBusinessLogical
    {
        MRLPriceByCatgDAL MRLPriceByCatgDAL = new MRLPriceByCatgDAL();

        #region public MRLPriceByCatgBLL()

        public MRLPriceByCatgBLL()
        {
        }

        #endregion

        #region Select

        public MRLPriceByCatgDEL SelectMRLPriceByCatgByRecID(DBAccess dBAccess, string strRecID)
        {
            MRLPriceByCatgDEL MRLPriceByCatgDEL = new MRLPriceByCatgDEL();

            DataFunctions.SelectByRecID(dBAccess, MRLPriceByCatgDEL, MRLPriceByCatgDAL.FieldNames, strRecID);

            return MRLPriceByCatgDEL;
        }

        public MRLPriceByCatgDEL SelectMRLPriceByCatgByRecID(string strRecID)
        {
            DBAccess dBAccess = new DBAccess(false, false);

            MRLPriceByCatgDEL MRLPriceByCatgDEL = null;

            try
            {
                MRLPriceByCatgDEL = SelectMRLPriceByCatgByRecID(dBAccess, strRecID);
            }
            catch (Exception e)
            {
                ExceptionManager.ProcessException(e);
            }
            finally
            {
                dBAccess.CloseCon();
            }
            return MRLPriceByCatgDEL;

        }

        public IDataEntity SelectDataByRecID(string strRecID)
        {
            DBAccess dBAccess = new DBAccess(false, false);
            try
            {
                MRLPriceByCatgDEL MRLPriceByCatgDEL = MRLPriceByCatgDAL.SelectDataByRecID(dBAccess, strRecID);
                return MRLPriceByCatgDEL as IDataEntity;
            }
            catch (Exception e)
            {
                ExceptionManager.ProcessException(e);
                return null;
            }
            finally
            {
                dBAccess.CloseCon();
            }
        }


        #endregion

        #region Insert into
        public bool Insert(IDataEntity iMRLPriceByCatgDEL)
        {
            MRLPriceByCatgDEL MRLPriceByCatgDEL = iMRLPriceByCatgDEL as MRLPriceByCatgDEL;
            DBAccess dBAccess = new DBAccess(false, true);
            MRLPriceByCatgBRL MRLPriceByCatgBRL = new MRLPriceByCatgBRL();

            try
            {
                if (MRLPriceByCatgBRL.InsertValid(dBAccess, MRLPriceByCatgDEL))
                {
                    //Insert Into MRLPriceByCatg
                    MRLPriceByCatgDAL.InsertMRLPriceByCatg(dBAccess, MRLPriceByCatgDEL);
                    dBAccess.CommitTranAndCloseCon();
                    return true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                    return false;
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }
        }
        #endregion

        #region Update

        public bool Update(IDataEntity iMRLPriceByCatgDEL)
        {
            MRLPriceByCatgDEL MRLPriceByCatgDEL = iMRLPriceByCatgDEL as MRLPriceByCatgDEL;
            DBAccess dBAccess = new DBAccess(false, true);
            MRLPriceByCatgBRL MRLPriceByCatgBRL = new MRLPriceByCatgBRL();

            try
            {
                if (MRLPriceByCatgBRL.UpdateValid(dBAccess, MRLPriceByCatgDEL))
                {
                    MRLPriceByCatgDAL.UpdateMRLPriceByCatg(dBAccess, MRLPriceByCatgDEL);
                    dBAccess.CommitTranAndCloseCon();
                    return true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                    return false;
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }
        }

        #endregion

        #region Delete

        public bool Delete(string strRecId, byte[] btOldRecStamp)
        {
            MRLPriceByCatgBRL MRLPriceByCatgBRL = new MRLPriceByCatgBRL();
            DBAccess dBAccess = new DBAccess(false, true);

            try
            {
                if (MRLPriceByCatgBRL.DeleteValid(dBAccess, strRecId, btOldRecStamp))
                {
                    MRLPriceByCatgDAL.DeleteMRLPriceByCatg(dBAccess, strRecId);

                    dBAccess.CommitTranAndCloseCon();
                    return true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                    return false;
                }


            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }
        }

        #endregion
    }
}
